package com.fr.report.web.ui;

import com.fr.base.ArrayUtils;
import com.fr.base.StringUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.web.Repository;

public class MultiFileEditor extends FieldEditor
{
  public static final String EVENT_UPLOAD_CALLBACK = "callback";
  private boolean autoUpload = true;
  private int maxLength = -1;
  private String url;
  private String accept;

  public boolean isAutoUpload()
  {
    return this.autoUpload;
  }

  public void setAutoUpload(boolean paramBoolean)
  {
    this.autoUpload = paramBoolean;
  }

  public void setMaxLength(int paramInt)
  {
    this.maxLength = paramInt;
  }

  public int getMaxLength()
  {
    return this.maxLength;
  }

  public void setUrl(String paramString)
  {
    this.url = paramString;
  }

  public String getUrl()
  {
    return this.url;
  }

  public void setAccept(String paramString)
  {
    this.accept = paramString;
  }

  public String getAccept()
  {
    return this.accept;
  }

  public String getXType()
  {
    return "multifile";
  }

  public String[] supportedEvents()
  {
    String[] arrayOfString = { "callback" };
    return ((String[])ArrayUtils.addAll(super.supportedEvents(), arrayOfString));
  }

  public JSONObject createJSONConfig(Object paramObject, Repository paramRepository)
    throws JSONException
  {
    JSONObject localJSONObject = super.createJSONConfig(paramObject, paramRepository);
    if (!(this.autoUpload))
      localJSONObject.put("autoUpload", false);
    if (!(StringUtils.isBlank(getUrl())))
      localJSONObject.put("url", getUrl());
    if (!(StringUtils.isEmpty(getAccept())))
      localJSONObject.put("accept", getAccept());
    if (this.maxLength != -1)
      localJSONObject.put("maxlength", this.maxLength);
    return localJSONObject;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("FileAttr")))
    {
      String str = null;
      if ((str = paramXMLableReader.getAttr("url")) != null)
        setUrl(str);
      if ((str = paramXMLableReader.getAttr("autoUpload")) != null)
        setAutoUpload(false);
      if ((str = paramXMLableReader.getAttr("maxlength")) != null)
        setMaxLength(Integer.parseInt(str));
      if ((str = paramXMLableReader.getAttr("accept")) != null)
        setAccept(str);
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("FileAttr");
    if (getUrl() != null)
      paramXMLPrintWriter.attr("url", getUrl());
    if (!(this.autoUpload))
      paramXMLPrintWriter.attr("autoUpload", this.autoUpload);
    if (this.maxLength != -1)
      paramXMLPrintWriter.attr("maxlength", this.maxLength);
    if (!(StringUtils.isEmpty(getAccept())))
      paramXMLPrintWriter.attr("accept", getAccept());
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof FileEditor))
      return false;
    return ComparatorUtils.equals(((MultiFileEditor)paramObject).getUrl(), getUrl());
  }
}